﻿using UnityEngine;
using System.Collections;

namespace CompleteProject
{
    public class CameraFollow : MonoBehaviour
    {
        public Transform target;            // The position that that camera will be following.
        public float zoom = 2f;        // The speed with which the camera will be following.
        public float max_zoom = 5f;
        public float min_zoom = 1f;

        public float angle;
        public float max_angle;
        public float min_angle;

        void Awake()
        {
            Gamecontrol.Instance.e_leader_change += delegate()
            {
                target = Gamecontrol.Instance.player_leader.gameObject.transform;
            };
        }
        
        void Start ()
        {
            
        }
        void Update()
        {
            if(Input.GetAxisRaw("Camera_angle") != 0) 
            {
                angle -= Input.GetAxisRaw("Camera_zoom");
                angle = Mathf.Clamp(angle, min_angle, max_angle);
            }
            else
            {
                zoom -= Input.GetAxisRaw("Camera_zoom");
                zoom = Mathf.Clamp(zoom, min_zoom, max_zoom);
            }
            transform.position = target.position + new Vector3(-1,angle,-1).normalized * zoom;
            transform.LookAt(target);
        }
    }
}